package borge.web.teamspirit.client.page.shared.widgets;

import borge.web.teamspirit.client.SessionData;
import borge.web.teamspirit.client.TeamSpirit;
import borge.web.teamspirit.client.TeamSpiritConstants;
import borge.web.teamspirit.client.data.Match;
import borge.web.teamspirit.client.data.Team;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler.WidgetEventType;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

public class CreateTeamWidget extends CreateDataWidget implements ClickHandler {

	private Team iTeam;
	
	public CreateTeamWidget(WidgetEventHandler aEventHandler){
		
        iPanel.add(iTable);
        initWidget(iPanel);
		
	}
	
	private void createDataTable(){
		
		if(iTeam == null)
			iTeam = new Team();
		
		TeamSpiritConstants lsc = TeamSpirit.getConstants();
        int row = 0;
        final int maxLength = 10;
        
        addTableRow(row++, new InputWrapper(lsc.name(), createTextBox(iTeam.getName(), maxLength), true));
        
        addButton(row, 0, this);	
	}
	
	@Override
	public void onClick(ClickEvent event) {
		// TODO Auto-generated method stub
		postEvent(WidgetEventType.TEAM_CREATED);
		
	}

	@Override
	public Team getDataObject() {
		// TODO Auto-generated method stub
		return iTeam;
	}

    @Override
	public void updateData() {
		
		iTeam = (Team)SessionData.sEditObject;
		SessionData.sEditObject = null;
		createDataTable();
	}
	
}
